package pub.guoxin.oops.vo;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * Created by guoxin on 17-10-18.
 */
@Component
public class ResultVoBuilder {

    public <T> ResultVo buildServerErrorResultInfo() {
        return new ResultVo<T>(HttpStatus.INTERNAL_SERVER_ERROR, null);
    }

    public <T> ResultVo buildSuccessResultInfo() {
        return new ResultVo<T>(HttpStatus.OK, null);
    }

    public <T> ResultVo buildSuccessResultInfo(String msg) {
        return new ResultVo<>(HttpStatus.OK.value(), msg, null);
    }

    public <T> ResultVo<T> buildSuccessResultInfo(T data) {
        return new ResultVo<>(HttpStatus.OK, data);
    }

    public <T> ResultVo<T> buildSuccessResultInfo(String msg, T data) {
        return new ResultVo<>(HttpStatus.OK.value(), msg, data);

    }


    public <T> ResultVo buildBadRequestResultInfo() {
        return new ResultVo<>(HttpStatus.BAD_REQUEST, null);

    }

    public <T> ResultVo buildBadRequestResultInfo(String msg) {
        return new ResultVo<>(HttpStatus.BAD_REQUEST.value(), msg, null);

    }

    public <T> ResultVo<T> buildBadRequestResultInfo(T data) {
        return new ResultVo<>(HttpStatus.BAD_REQUEST, data);

    }

    public <T> ResultVo buildBadRequestResultInfo(String msg, T data) {
        return new ResultVo<>(HttpStatus.BAD_REQUEST.value(), msg, data);

    }

    public <T> ResultVo buildNotFoundResultInfo() {
        return new ResultVo<>(HttpStatus.NOT_FOUND, null);

    }

    public <T> ResultVo buildNotFoundResultInfo(String msg) {
        return new ResultVo<>(HttpStatus.NOT_FOUND.value(), msg);

    }

    /**
     * 使用{@link HttpStatus}构建响应
     *
     * @param status
     * @return
     */
//    public <T> ResultVo buildInfo(HttpStatus status) {
//        return new ResultVo<>(status.value(), status.getReasonPhrase());
//
//    }

    /**
     * 使用{@link HttpStatus}构建响应
     *
     * @param status
     * @return
     */
    public <T> ResultVo buildInfo(HttpStatus status) {
        return new ResultVo<>(status.value(), status.getReasonPhrase());

    }

    public <T> ResultVo buildInfo(int code, String msg, T data) {
        return new ResultVo<>(code, msg, data);
    }

}
